<?php
// +----------------------------------------------------------------------+
// | Author:  Evgeny Leontev <eleontev@gmail.com>                         |
// | Copyright (c) 2005 Evgeny Leontev                                    |
// +----------------------------------------------------------------------+
// | This source file is free software; you can redistribute it and/or    |
// | modify it under the terms of the GNU Lesser General Public           |
// | License as published by the Free Software Foundation; either         |
// | version 2.1 of the License, or (at your option) any later version.   |
// |                                                                      |
// | This source file is distributed in the hope that it will be useful,  |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
// | Lesser General Public License for more details.                      |
// +----------------------------------------------------------------------+

require_once 'eleontev/URL/RequestDataUtil.php';


class RequestData
{
	
	var $int_keys = array();
	var $skip_keys = array();
	var $html_keys = array();
	var $html_values = array();
	var $wordrap_num = 0;  //default: no wordwrap
	
	
	
	// array: key is that we can access it, value is custom real param
	// for example: real $_GET['custom'] = 20; we can access it like $rq->action, 
	// so on page we always can write $rq->action
	// access any var we want just change value for $predefined array for that key
	//var $predefined = array('action'=>'_a');
	var $predefined = array();
	var $vars = array();
	
	var $action; // to have it on page
	
	
	function RequestData(&$var) {
		$this->setVars($var);
	}
	
	function setIntKeys($key) {
		$this->int_keys[] = $key;
	}	
	
	function setSkipKeys($key) {
		$this->skip_keys[] = $key;
	}

	function setHtmlKeys($key) {
		$this->html_keys[$key] = $key;
	}
	
	// the same as setHtmlKeys 
	function setHtmlValues($key) {
		$this->setHtmlKeys($key);
	}
	
	
	function getHtmlValues() {
		
		$arr = array();
		foreach($this->html_keys as $v) {
			$arr[$v] = &$this->vars[$v];
		}

		return $arr;
	}
	
	function &setVars(&$var) {
		
		//if(!checkPHP()) { // check for php 5.2.0
			$this->setVarsPHP4($var);
		//}
		
		$this->vars =& $var;
		$this->toInt();
		
		return $this->vars;
	}
	
	
	// I do not like it at all
	function setVarsPHP4(&$arr) {
		foreach($arr as $k => $v){
			$this->$k =& $arr[$k];
		}
	}
	
	
/*
	function __set($nm, $val) { //print "Setting [$nm] to $val\n<br>"; 
		if(isset($this->predefined[$nm])) {
			$this->vars[$this->predefined[$nm]] = $val; 
		} else {
			$this->vars[$nm] = $val; 
		}
	}
	
	
	function __get($nm) { //print "Getting [$nm]\n<br>"; 
		if(isset($this->predefined[$nm])) {
			$t = $this->vars[$this->predefined[$nm]]; 
		} elseif (isset($this->vars[$nm])) {
			$t = $this->vars[$nm]; 
		}
		
		if($t === false) {
			return $t; 
		} else {
			echo "Undefined property <b>$nm</b>";
			//echo __FILE__ . '(' . __LINE__ . ')' . __METHOD__; 
		}
	} 
*/
	
	 
	function toInt() {
		return RequestDataUtil::toInt($this->vars, $this->int_keys);
	}
	
	// $param true, false (for server check) or real values
	function stripVars($server_check = false) {
		
		$skip = array_merge($this->skip_keys, $this->html_keys);
		$html_values = $this->getHtmlValues();
			
		RequestDataUtil::stripVars($this->vars, $skip, $server_check, $this->wordrap_num);
		RequestDataUtil::stripVarsHtml($html_values, array(), $server_check);
	}
	
	
	// $param true, false (for server check) or real values
	function &stripVarsValues(&$values, $server_check = 'display') {
		$this->vars = &$values;
		$this->stripVars($server_check);
		
		return $this->vars;
	}
}



class FilterRequestData
{

	var $filters = array();
	
	
	function setFilter($func_name) {
		$this->filters[] = $func_name;
	}	
	
	
	
}
?>